﻿namespace Builder
{
    internal class HTMLBuilder : Builder
    {
        private string filename;
        private StreamWriter writer;
        public override void Close()
        {
            writer.WriteLine("</body></html>");
            writer.Close();
        }

        public override void MakeItems(string[] items)
        {
            writer.WriteLine("<ul>");
            foreach (var item in items)
            {
                writer.WriteLine($"<li>{item}</li>");
            }
            writer.WriteLine("</ul>");
        }

        public override void MakeString(string str)
        {
            writer.WriteLine($"<p>{str}</p>");
        }

        public override void MakeTitle(string title)
        {
            filename = $"{title}.html";
            writer = new StreamWriter(filename);
            writer.Write($"<html><head><title>{title}</title></head><body>");
            writer.Write($"<h1>{title}</h1>" );
        }

        public string GetResult() 
        {
            return filename;
        }
    }
}
